﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Audio;

namespace Project1
{
    public class GrassField 
    {
        #region Member Variables

        /// <summary>
        /// A handle to our game
        /// </summary>
        TurretGame mGame;

        /// <summary>
        /// The turret model
        /// </summary>
        Model mModel;


        #endregion

        #region Properties

        #endregion

        public GrassField(TurretGame aGame)
        {
            this.mGame = aGame;

        }
        /// <summary>
        /// This function is called to load content into
        /// our game
        /// </summary>
        /// <param name="aContent"></param>
        public void  LoadContent(ContentManager aContent)
        {
            mModel = aContent.Load<Model>("FootballField");
        }

        /// <summary>
        /// This function is called to update this component 
        /// to the current game time
        /// </summary>
        /// <param name="aGameTime"></param>
        public void Update(GameTime aGameTime)
        {
        }

        /// <summary>
        /// This function is called to draw this game component
        /// </summary>
        /// <param name="aGraphics"></param>
        /// <param name="aGameTime"></param>
        public void Draw(GraphicsDeviceManager aGraphics, GameTime aGameTime)
        {
            DrawModel(aGraphics, mModel, Matrix.Identity);

        }

        /// <summary>
        /// This function will draw the model
        /// </summary>
        /// <param name="aGraphics"></param>
        /// <param name="aModel"></param>
        /// <param name="aWorld"></param>
        private void DrawModel(GraphicsDeviceManager aGraphics, Model aModel, Matrix aWorld)
        {
            Matrix[] lTransforms = new Matrix[aModel.Bones.Count];
            aModel.CopyAbsoluteBoneTransformsTo(lTransforms);

            foreach (ModelMesh lMesh in aModel.Meshes)
            {
                foreach (BasicEffect lEffect in lMesh.Effects)
                {
                    lEffect.EnableDefaultLighting();
                    lEffect.World = lTransforms[lMesh.ParentBone.Index] * aWorld;
                    int lTemp = lMesh.ParentBone.Index;
                    lEffect.View = mGame.Camera.View;
                    lEffect.Projection = mGame.Camera.Projection;
                }
                lMesh.Draw();
            }
        }

    }
}
